﻿using HMIControl;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace CoreTest
{



    /// <summary>
    /// Batching_SBT.xaml 的交互逻辑
    /// </summary>
    public partial class SiloProductLine : UserControl
    {
        List<TagNodeHandle> _valueChangedList;

        public SiloProductLine()
        {
            InitializeComponent();
        }

        private void HMI_Loaded(object sender, RoutedEventArgs e)
        {
            lock (this)
            {
                _valueChangedList = cvs1.BindingToServer(App.Server);
            }
            ben1.CommandCb = new Action<ValueSelectSwitch, string>(LoRaDO1Command_Sub);
        }

        private void LoRaDO1Command_Sub(ValueSelectSwitch Switch, string tag)
        {
            if (Switch.IsChecked == true)
            {
                App.Server[tag].Write(Switch.RightValue);
            }
            else
            {
                App.Server[tag].Write(Switch.LeftValue);
            }
        }

        private void HMI_Unloaded(object sender, RoutedEventArgs e)
        {
            lock (this)
            {
                App.Server.RemoveHandles(_valueChangedList);
            }
        }

        private void mt12_run_Click(object sender, RoutedEventArgs e)
        {
            var obj = App.Server["LoRaDO2"];
            obj.Write(1);
            obj.Write(0);
        }
    }


}
